package com.easy.generator.vue;

import com.easy.generator.Easy;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.time.LocalDate;

/**
 * @author easy
 * @date 2025年07月11日 14:45
 */
public class Index_Generator {
    private static final String DIR_NAME = Easy.VUE_LOCAL_PATH;
    private static final String FILE_NAME = "index.html";
    private static final String FILE_TEMPLATE =
            "<!DOCTYPE html>\n" +
                    "<html lang=\"\">\n" +
                    "  <head>\n" +
                    "    <meta charset=\"UTF-8\">\n" +
                    "    <link rel=\"icon\" href=\"./src/assets/logo.png\">\n" +
                    "    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n" +
                    "    <title>Vite App</title>\n" +
                    "  </head>\n" +
                    "  <body>\n" +
                    "    <div id=\"app\"></div>\n" +
                    "    <script type=\"module\" src=\"/src/main.js\"></script>\n" +
                    "  </body>\n" +
                    "</html>\n";

    public static void generate() throws IOException {
        String content = String.format(FILE_TEMPLATE, LocalDate.now());
        File outputFile = new File( DIR_NAME+ "/" + FILE_NAME);
        if (!outputFile.exists()) {
            outputFile.getParentFile().mkdirs();
            outputFile.createNewFile();
        }
        try (FileWriter writer = new FileWriter(outputFile)) {
            writer.write(content);
        }
        System.out.println("已生成文件：" + outputFile.getAbsolutePath());
    }
}
